<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增市政收入报表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }

    .gray-bg {
        background-color: #FFFFFF;
    }

    form {
        white-space: nowrap;
    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content" id="dv">
    <form class="form-horizontal m" id="add" AUTOCOMPLETE="OFF">
        <input type="hidden" id="companyId" name="companyId">
        <input type="hidden" id="programName" name="programName">
        <input type="hidden" id="programId" name="programId">
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">出租单位 ：</label>
                    <div class="col-sm-8">
                        <select id="rentalId" name="rentalId" class="form-control">
                            <option value="">请选择</option>
                            <option th:each="name : ${rentalNames}" th:text="${name.dictLabel}"
                                    th:value="${name.dictCode}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">机械编号类型：</label>
                    <div class="col-sm-8">
                        <select id="machineryNumberId" name="machineryNumberId" class="form-control" required>

                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">进场时间 ：</label>
                    <div class="col-sm-8">
                        <input id="entryTime" name="entryTime" class="form-control" placeholder="yyyy-mm-dd"
                               type="text">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">退场时间：</label>
                    <div class="col-sm-8">
                        <input id="exitTime" name="exitTime" class="form-control" placeholder="yyyy-mm-dd"
                               type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">租凭单价：</label>
                    <div class="col-sm-8">
                        <input id="rentalUnitPrice" name="rentalUnitPrice" class="form-control" placeholder="请输入租凭单价(元/月)"
                               type="number" required>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">柴油单价 ：</label>
                    <div class="col-sm-8">
                        <input id="dieselUnitPrice" name="dieselUnitPrice" class="form-control" placeholder="请输入柴油单价(元/L)"
                               type="number" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">税率：</label>
                    <div class="col-sm-8">
                        <input id="taxRate" name="taxRate" class="form-control" placeholder="请输入税率"
                               type="number" required>
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">需扣除费用：</label>
                    <div class="col-sm-8">
                        <input id="deductionExpense" name="deductionExpense" class="form-control" placeholder="请输入需扣除费用(元)"
                               type="number" required>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">每月一填</h4>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">实际月份 ：</label>
                    <div class="col-sm-8">
                        <input id="actualMonth" name="actualMonth" class="form-control" placeholder="请选择月份"
                               type="text" required>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">备注 ：</label>
                    <div class="col-sm-8">
                        <textarea id="remark" name="remark" class="form-control"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">月末加油量 ：</label>
                    <div class="col-sm-8">
                        <input id="monthEndFuelConsumption" name="monthEndFuelConsumption" class="form-control"
                               placeholder="请输入月末加油量(L)"
                               type="number" required>
                    </div>
                </div>

                <!--<div class="col-sm-6">-->
                    <!--<label class="col-sm-4 control-label">本月剩余油量 ：</label>-->
                    <!--<div class="col-sm-8">-->
                        <!--<input id="currentMonthSurplusDiesel" name="currentMonthSurplusDiesel" class="form-control"-->
                               <!--placeholder="请输入本月剩余油量(L)"-->
                               <!--type="number" required>-->
                    <!--</div>-->
                <!--</div>-->
            </div>
        </div>
    </form>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>

<script th:inline="javascript">
    var prefix = ctx + "manage";
    $(function () {
        /* 初始化 数据 */
        $("#companyId").val([[${companyId}]]);
        $("#programId").val([[${programId}]]);
        $("#programName").val([[${programName}]]);

        layui.use('laydate', function () {
            var laydate = layui.laydate;
            var start = laydate.render({
                elem: '#entryTime',
                type: 'date',
                done: function (value, date) {
                    // 结束时间大于开始时间
                    if (value !== '') {
                        end.config.min.year = date.year;
                        end.config.min.month = date.month - 1;
                        end.config.min.date = date.date;
                    } else {
                        end.config.min.year = '';
                        end.config.min.month = '';
                        end.config.min.date = '';
                    }
                }
            });
            var end = laydate.render({
                elem: '#exitTime',
                type: 'date',
                done: function (value, date) {
                    // 开始时间小于结束时间
                    if (value !== '') {
                        start.config.max.year = date.year;
                        start.config.max.month = date.month - 1;
                        start.config.max.date = date.date;
                    } else {
                        start.config.max.year = '';
                        start.config.max.month = '';
                        start.config.max.date = '';
                    }
                }
            });
            laydate.render({
                elem: '#actualMonth',
                type: 'month'
            });
        });

        $("#rentalId").change(function () {
            if ($("#rentalId").val() != "") {
                $.ajax({
                    url: prefix + '/selectMaterNameByCode?dictCode=' + $("#rentalId").val(),
                    success: function (data) {
                        $("#machineryNumberId").empty();
                        for (var i = 0; i < data.materNames.length; i++) {
                            $("#machineryNumberId").append('<option value="' + data.materNames[i].id + '">' + data.materNames[i].lable + '</option>');
                        }
                    }
                })
            } else {
                $("#machineryNumberId").empty();
            }

        })
    })


    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#add").serializeArray();
            data.push({
                name: 'rentalType',
                value: '1'
            });
            $.operate.save(prefix + "/saveMachineryMonth", data);
            parent.refresh();
        }
    }

</script>
</body>
</html>